package bavaria.hightec.formatter;

import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.ResourceBundle;

import bavaria.hightec.banking.Account;
import bavaria.hightec.banking.Accounting;
import bavaria.hightec.banking.BankImpl;
import bavaria.hightec.banking.ConvertMoney;
import bavaria.hightec.exceptions.UnknownLanguageException;

public class StatementFormatterHTMLTextImpl implements StatementFormatter{
	ResourceBundle statement;
    String value = null;
	private StringBuffer sb;
	private boolean end = false;
//	NumberFormat numberFormatter;
	DateFormat dateFormatter;
	
	public StatementFormatterHTMLTextImpl() throws UnknownLanguageException{
		statement=BankImpl.getLocale();
//		numberFormatter = numberFormatter.getCurrencyInstance(BankImpl.getLocale().getLocale());
		dateFormatter= dateFormatter.getDateInstance(2, BankImpl.getLocale().getLocale());
		value=statement.getString("STATEMENT");
		sb= new StringBuffer("<html> \n  " +
							"<head> \n " +
							"<title>" + value + "</title> \n " +
							"</head> \n " +
							"<body> \n ");
	}
	
	public void addAccount(Account account){
		value=statement.getString("OWNER");
		sb.append("<p>"+ value + ": " + account.getAccountHolder() + "</p>");
		value=statement.getString("ACCOUNTNUMBER");
		sb.append("<p>" + value + ": " + account.getAccountNumber() + "</p>");
		value=statement.getString("BALANCE");
		sb.append("<p>" + value + ": " + account.getBalance() + "</p><br>");
	}
	
	public void addTransaction(Accounting transaction){
		value=statement.getString("DATE");
		sb.append("<p>" + value + ": " + dateFormatter.format(transaction.getDate())+ "</p>");
		value=statement.getString("AMOUNT");
		sb.append("<p>" + value + ": " + ConvertMoney.convert(transaction.getAmount().getAmount(),transaction.getAmount().getCurrency())+ "</p>");
		value=statement.getString("MATTER");
		sb.append("<p>" + value + ": " + transaction.getMatter()+ "</p><br>");
	}
	
	
	
	public String getStatement(){
		if(end == false){
			sb.append("</body> \n  " +
					"</html>");
			end = true;
		}
		return sb.toString();
	}

}
